<?php

namespace App\Http\Controllers\Admin;

use App\Http\Filters\AppUserFilter;
use App\Models\AppUser;
use App\Http\Requests\AppUserRequest;
use App\Http\Resources\AppUserResource;
use Illuminate\Http\Request;

class AppUserController extends Controller
{
    public function index(AppUserFilter $filter)
    {
        $appUsers = AppUser::query()
            ->filter($filter)
            ->paginate();

        return $this->ok(AppUserResource::collection($appUsers));
    }

    public function create()
    {
        return $this->ok();
    }

    public function store(AppUserRequest $request)
    {
        $inputs = $request->validated();
        $appUser = AppUser::create($inputs);

        return $this->created(AppUserResource::make($appUser));
    }

    public function edit(Request $request, AppUser $appUser)
    {
        return $this->ok(AppUserResource::make($appUser));
    }

    public function update(AppUserRequest $request, AppUser $appUser)
    {
        $inputs = $request->validated();
        $appUser->update($inputs);

        return $this->created(AppUserResource::make($appUser));
    }

    public function destroy(AppUser $appUser)
    {
        $appUser->delete();
        return $this->noContent();
    }
}
